package com.ctgu.common.util.baidu;

import com.ctgu.common.config.baidu.BaiduAIFace;
import com.ctgu.common.config.baidu.SettingModel;
import com.ctgu.module.admin.model.User;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Map;

@Component
public class FaceLoginUtil {

    @Autowired
    BaiduAIFace faceApi;

    @Autowired
    SettingModel settingModel;

    public Map<String,Object> searchFace(String imageBase64) throws IOException {
        String substring = imageBase64.substring(imageBase64.indexOf(",") + 1, imageBase64.length());
        settingModel.setImgPath(substring);
        settingModel.setGroupID("StRoot");
        Map map = faceApi.FaceSearch(settingModel);
        System.out.println(map);
        return map;
    }

    public Map<String,Object> addFace(String imageBase64) throws IOException {
        User user = (User) SecurityUtils.getSubject().getPrincipal();

        String substring = imageBase64.substring(imageBase64.indexOf(",") + 1, imageBase64.length());
        settingModel.setImgPath(substring);
        settingModel.setGroupID("StRoot");
        settingModel.setUserID(user.getUserId());
        Map map = faceApi.FaceRegistration(settingModel);
        return map;
    }
}
